package idv.loveloser.dao;

import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * MdlGlossary entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see idv.loveloser.dao.MdlGlossary
 * @author MyEclipse Persistence Tools
 */

public class MdlGlossaryDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory
			.getLogger(MdlGlossaryDAO.class);
	// property constants
	public static final String COURSE = "course";
	public static final String NAME = "name";
	public static final String INTRO = "intro";
	public static final String INTROFORMAT = "introformat";
	public static final String ALLOWDUPLICATEDENTRIES = "allowduplicatedentries";
	public static final String DISPLAYFORMAT = "displayformat";
	public static final String MAINGLOSSARY = "mainglossary";
	public static final String SHOWSPECIAL = "showspecial";
	public static final String SHOWALPHABET = "showalphabet";
	public static final String SHOWALL = "showall";
	public static final String ALLOWCOMMENTS = "allowcomments";
	public static final String ALLOWPRINTVIEW = "allowprintview";
	public static final String USEDYNALINK = "usedynalink";
	public static final String DEFAULTAPPROVAL = "defaultapproval";
	public static final String GLOBALGLOSSARY = "globalglossary";
	public static final String ENTBYPAGE = "entbypage";
	public static final String EDITALWAYS = "editalways";
	public static final String RSSTYPE = "rsstype";
	public static final String RSSARTICLES = "rssarticles";
	public static final String ASSESSED = "assessed";
	public static final String ASSESSTIMESTART = "assesstimestart";
	public static final String ASSESSTIMEFINISH = "assesstimefinish";
	public static final String SCALE = "scale";
	public static final String TIMECREATED = "timecreated";
	public static final String TIMEMODIFIED = "timemodified";
	public static final String COMPLETIONENTRIES = "completionentries";

	public void save(MdlGlossary transientInstance) {
		log.debug("saving MdlGlossary instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(MdlGlossary persistentInstance) {
		log.debug("deleting MdlGlossary instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public MdlGlossary findById(java.lang.Long id) {
		log.debug("getting MdlGlossary instance with id: " + id);
		try {
			MdlGlossary instance = (MdlGlossary) getSession().get(
					"idv.loveloser.dao.MdlGlossary", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(MdlGlossary instance) {
		log.debug("finding MdlGlossary instance by example");
		try {
			List results = getSession()
					.createCriteria("idv.loveloser.dao.MdlGlossary")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding MdlGlossary instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from MdlGlossary as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByCourse(Object course) {
		return findByProperty(COURSE, course);
	}

	public List findByName(Object name) {
		return findByProperty(NAME, name);
	}

	public List findByIntro(Object intro) {
		return findByProperty(INTRO, intro);
	}

	public List findByIntroformat(Object introformat) {
		return findByProperty(INTROFORMAT, introformat);
	}

	public List findByAllowduplicatedentries(Object allowduplicatedentries) {
		return findByProperty(ALLOWDUPLICATEDENTRIES, allowduplicatedentries);
	}

	public List findByDisplayformat(Object displayformat) {
		return findByProperty(DISPLAYFORMAT, displayformat);
	}

	public List findByMainglossary(Object mainglossary) {
		return findByProperty(MAINGLOSSARY, mainglossary);
	}

	public List findByShowspecial(Object showspecial) {
		return findByProperty(SHOWSPECIAL, showspecial);
	}

	public List findByShowalphabet(Object showalphabet) {
		return findByProperty(SHOWALPHABET, showalphabet);
	}

	public List findByShowall(Object showall) {
		return findByProperty(SHOWALL, showall);
	}

	public List findByAllowcomments(Object allowcomments) {
		return findByProperty(ALLOWCOMMENTS, allowcomments);
	}

	public List findByAllowprintview(Object allowprintview) {
		return findByProperty(ALLOWPRINTVIEW, allowprintview);
	}

	public List findByUsedynalink(Object usedynalink) {
		return findByProperty(USEDYNALINK, usedynalink);
	}

	public List findByDefaultapproval(Object defaultapproval) {
		return findByProperty(DEFAULTAPPROVAL, defaultapproval);
	}

	public List findByGlobalglossary(Object globalglossary) {
		return findByProperty(GLOBALGLOSSARY, globalglossary);
	}

	public List findByEntbypage(Object entbypage) {
		return findByProperty(ENTBYPAGE, entbypage);
	}

	public List findByEditalways(Object editalways) {
		return findByProperty(EDITALWAYS, editalways);
	}

	public List findByRsstype(Object rsstype) {
		return findByProperty(RSSTYPE, rsstype);
	}

	public List findByRssarticles(Object rssarticles) {
		return findByProperty(RSSARTICLES, rssarticles);
	}

	public List findByAssessed(Object assessed) {
		return findByProperty(ASSESSED, assessed);
	}

	public List findByAssesstimestart(Object assesstimestart) {
		return findByProperty(ASSESSTIMESTART, assesstimestart);
	}

	public List findByAssesstimefinish(Object assesstimefinish) {
		return findByProperty(ASSESSTIMEFINISH, assesstimefinish);
	}

	public List findByScale(Object scale) {
		return findByProperty(SCALE, scale);
	}

	public List findByTimecreated(Object timecreated) {
		return findByProperty(TIMECREATED, timecreated);
	}

	public List findByTimemodified(Object timemodified) {
		return findByProperty(TIMEMODIFIED, timemodified);
	}

	public List findByCompletionentries(Object completionentries) {
		return findByProperty(COMPLETIONENTRIES, completionentries);
	}

	public List findAll() {
		log.debug("finding all MdlGlossary instances");
		try {
			String queryString = "from MdlGlossary";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public MdlGlossary merge(MdlGlossary detachedInstance) {
		log.debug("merging MdlGlossary instance");
		try {
			MdlGlossary result = (MdlGlossary) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(MdlGlossary instance) {
		log.debug("attaching dirty MdlGlossary instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(MdlGlossary instance) {
		log.debug("attaching clean MdlGlossary instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}